#!/usr/bin/perl

my (%config);

$config{'qmaildir'} = "/etc/nas/qmaildir.conf";
$config{'flink_domains'} = "/home/vpopmail/domains";
$config{'flink_queue'} = "/var/qmail/queue";
$config{'flink_temp'} = "/var/www/html/igenus/temp";


#qmail_dir_get()
sub qmail_dir_get()
{
    my (@file, $i, @line, $mailroot);

    open(MDIRCONF, $config{'qmaildir'});
    @file = <MDIRCONF>;
    close(MDIRCONF);

    for ($i = 0; $i < @file; $i++)
    {
	chomp($file[$i]);
	$file[$i] =~ s/#.*$//;

	@line = split ("=", $file[$i]);
	if ($line[0] eq 'MAILROOT')
	{
	    $mailroot = $line[1];
	    last;
	}	
    }

    return $mailroot;
}


#====================================================
#          main  function                           =
#   remove all filelink and relink filelink         =
#   in current .mailroot/[domains|queue|temp]       =
#====================================================

my ($mailroot);
my ($queuedir, $domainsdir, $tempdir);

$mailroot = &qmail_dir_get();

$queuedir = $mailroot . 'queue';
$domainsdir = $mailroot . 'domains';
$tempdir = $mailroot . 'temp';

if (-d $mailroot)
{
    $out = system('rm', '-f', $config{'flink_queue'});
    $out = system('ln', '-s', $queuedir, $config{'flink_queue'});
    $out = system('rm', '-f', $config{'flink_domains'});
    $out = system('ln', '-s', $domainsdir, $config{'flink_domains'});
    $out = system('rm', '-f', $config{'flink_temp'});
    $out = system('ln', '-s', $tempdir, $config{'flink_temp'});
}
